#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back

using namespace std;

typedef long long ll;
typedef double db;
typedef vector < int > vec;
typedef pair < int , int > pii;

int read() {
    int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int N = 1e5 + 10,B = 315,mod = 1e9 + 7;

int a[N],b[N],c[N],n,Q,bel[N];
int pronc[N];

struct BLOCK {
    int L,R,mxc,lz,len,ans,st;
    int pro[B + 10],c[B + 10];
    struct data { int val,id; } b[B + 10];
    friend bool operator < (data a,data b) { return a.val < b.val; }
    void build(int l,int r) {
	L = l; R = r; lz = -1; pro[0] = ans = 1; len = r - l + 1; mxc = 0;
	for(int i = l;i <= r;i++) c[i - l + 1] = :: c[i],mxc = max(mxc,c[i - l + 1]),b[i - l + 1] = (data) { :: b[i] , i - l + 1};
	sort(b + 1,b + len + 1); st = 1;
	for(int i = 1;i <= len;i++) pro[i] = (ll) pro[i - 1] * b[i].val % mod,ans = (ll) ans * min(b[i].val,c[b[i].id]) % mod;
    }
    int getc(int pos) { return lz == - 1 ? c[pos - L + 1] : lz; }
    void pushdn() { if(lz == -1) return; for(int i = 1;i <= len;i++) c[i] = lz; lz = -1; }
    void modifyb(int x,int y) {
	pushdn(); int pos = 0;
	for(int i = 1;i <= len;i++) if(b[i].id == x - L + 1) { pos = i; break; }
	b[pos].val = y; while(pos < len && b[pos].val > b[pos + 1].val) swap(b[pos],b[pos + 1]),pos++;
	pro[0] = ans = 1; st = 1;
	for(int i = 1;i <= len;i++) pro[i] = (ll) pro[i - 1] * b[i].val % mod,ans = (ll) ans * min(b[i].val,c[b[i].id]) % mod;
    }
    void modifyc(int xl,int xr,int nc) {
	pushdn(); for(int i = xl - L + 1;i <= xr - L + 1;i++) c[i] = nc; ans = 1; mxc = max(mxc,nc);
	st = 1; for(int i = 1;i <= len;i++) ans = (ll) ans * min(b[i].val,c[b[i].id]) % mod;
    }
    void modifyall(int nc) {
	lz = mxc = nc; while(st <= len && b[st].val <= nc) st++; ans = (ll) pro[st - 1] * pronc[len - st + 1] % mod;
    }
} t[N / B + 10];

int getr(int x) {
    for(int i = 1;i <= bel[n];i++)
	if(t[i].mxc >= x) 
	    for(int j = t[i].L;j <= t[i].R;j++)
		if(t[i].getc(j) >= x) return j - 1;
    return n;
}

void modifyc(int xl,int xr,int nc) {
    if(bel[xl] == bel[xr]) return t[bel[xl]].modifyc(xl,xr,nc);
    t[bel[xl]].modifyc(xl,t[bel[xl]].R,nc); t[bel[xr]].modifyc(t[bel[xr]].L,xr,nc);
    for(int i = bel[xl] + 1;i < bel[xr];i++) t[i].modifyall(nc);
}

int calc() { int ans = 1; for(int i = 1;i <= bel[n];i++) ans = (ll) ans * t[i].ans % mod; return ans; }

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin); freopen("1.out","w",stdout);
#endif
    n = in,Q = in; for(int i = 1;i <= n;i++) a[i] = in,c[i] = max(c[i - 1],a[i]); for(int i = 1;i <= n;i++) b[i] = in;
    for(int i = 1;i <= n;i++) bel[i] = (i - 1) / B + 1,t[bel[i]].R = i;
    for(int i = 1;i <= bel[n];i++) t[i].L = t[i - 1].R + 1;
    for(int i = 1;i <= bel[n];i++) t[i].build(t[i].L,t[i].R);
    while(Q--) {
	int op = in,x = in,y = in;
	if(op == 1) t[bel[x]].modifyb(x,y);
	else if(t[bel[x]].getc(x) < y) {
	    int r = getr(y); pronc[0] = 1; for(int i = 1;i <= B + 2;i++) pronc[i] = (ll) pronc[i - 1] * y % mod;
	    modifyc(x,r,y);
	}
	printf("%d\n",calc());
    }
}
